package com.canaan.business.service.barcode.impl;


import com.canaan.business.domain.barcode.UploadCircubill;
import com.canaan.business.mapper.barcode.UploadCircubillMapper;
import com.canaan.business.service.barcode.IUploadCircubillService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 监管码Service业务层处理
 *
 * @author yangjie
 * @date 2025-01-15
 */

@Service
public class UploadCircubillServiceImpl implements IUploadCircubillService {
    @Resource
    private UploadCircubillMapper uploadCircubillMapper;

    /**
     * 查询监管码
     *
     * @param id 监管码主键
     * @return 监管码
     */
    @Override
    public UploadCircubill selectUploadCircubillById(Long id) {
        return uploadCircubillMapper.selectUploadCircubillById(id);
    }

    /**
     * 查询监管码列表
     *
     * @param uploadCircubill 监管码
     * @return 监管码
     */
    @Override
    public List<UploadCircubill> selectUploadCircubillList(UploadCircubill uploadCircubill) {
        return uploadCircubillMapper.selectUploadCircubillList(uploadCircubill);
    }

    /**
     * 新增监管码
     *
     * @param uploadCircubill 监管码
     * @return 结果
     */
    @Override
    public int insertUploadCircubill(UploadCircubill uploadCircubill) {
        return uploadCircubillMapper.insertUploadCircubill(uploadCircubill);
    }

    /**
     * 批量新增监管码
     *
     * @param uploadCircubillList 监管码列表
     * @return 结果
     */
    @Override
    public int batchInsertUploadCircubill(List<UploadCircubill> uploadCircubillList) {
        for (UploadCircubill uploadCircubill : uploadCircubillList) {
            int insertNum = 0;
            for (int i = 0; i < uploadCircubillList.size(); ) {
                int endIndex = i + 500;
                if (endIndex > uploadCircubillList.size()) {
                    endIndex = uploadCircubillList.size();
                }
                insertNum = insertNum + uploadCircubillMapper.batchInsertUploadCircubill(uploadCircubillList.subList(i, endIndex));
                i = endIndex;
            }
            return insertNum;
        }
        return 0;
    }

    /**
     * 修改监管码
     *
     * @param uploadCircubill 监管码
     * @return 结果
     */
    @Override
    public int updateUploadCircubill(UploadCircubill uploadCircubill) {
        return uploadCircubillMapper.updateUploadCircubill(uploadCircubill);
    }

    /**
     * 批量修改监管码
     *
     * @param uploadCircubillList 监管码列表
     * @return 结果
     */
    @Override
    public int batchUpdateUploadCircubill(List<UploadCircubill> uploadCircubillList) {
        for (UploadCircubill uploadCircubill : uploadCircubillList) {
            int updateNum = 0;
            for (int i = 0; i < uploadCircubillList.size(); ) {
                int endIndex = i + 500;
                if (endIndex > uploadCircubillList.size()) {
                    endIndex = uploadCircubillList.size();
                }
                updateNum = updateNum + uploadCircubillMapper.batchUpdateUploadCircubill(uploadCircubillList.subList(i, endIndex));
                i = endIndex;
            }
            return updateNum;
        }
        return 0;
    }

    /**
     * 批量删除监管码
     *
     * @param ids 需要删除的监管码主键集合
     * @return 结果
     */
    @Override
    public int deleteUploadCircubillByIds(Long[] ids) {
        return uploadCircubillMapper.deleteUploadCircubillByIds(ids);
    }

    /**
     * 删除监管码信息
     *
     * @param id 监管码主键
     * @return 结果
     */
    @Override
    public int deleteUploadCircubillById(Long id) {
        return uploadCircubillMapper.deleteUploadCircubillById(id);
    }
}
